package tree.leetcode_108_easy;

public class SortedArrayToBST {
    public TreeNode sortedArrayToBST(int[] nums){
        return dfs(nums,0,nums.length - 1);
    }
    public TreeNode dfs(int[] nums, int left, int right){
        if(left > right){
            return null;
        }
        int mid = left + (right - left) / 2;
        TreeNode root = new TreeNode(nums[mid]);
        //分治，用左闭右闭区间更好
        root.left = dfs(nums,left,mid - 1);
        root.right = dfs(nums,mid + 1, right);
        return root;
    }
}
